/**********************************************************************************
 * Code license:  GNU General Public License v3                                   *
 * Main page:     https://code.google.com/p/library-cross-platform/               *
 * Issue tracker: https://code.google.com/p/library-cross-platform/issues/list    *
***********************************************************************************/

package library.compiler;

public class String implements Variable {

  protected char value[];
  protected int  buf_size = 50;
  
  public String() {
  }

  public String(char value) {
    this.value = new char[buf_size];
    this.value[0] = value;
  }

  public String(char[] value) {
    this.value    = value;
    this.buf_size = value.length;
  }

  public String(String value) {
    this.value    = value.value;
    this.buf_size = value.buf_size;
  }

  public char[] value() {
    return value;
  }
  
  public char value(int index) {
    return value[index];
  }
  
  public int length() {
    int index = 0;
    while(value[index] != '\0' && index < value.length)
     index ++;
    return index;
  }
  
  public int size() {
    return value.length;
  }
  
/**
 * operator '==' 
 * @param type
 * @return if type is equal this then true otherwise false
 */
  public boolean equal(Variable type) {
    boolean retvalue   = true;
    int     icount     = 0;
    String  stype      = (String)type;
    int     thislength = length();
    int     typelength = stype.length();

    if(thislength == typelength) {
      while(icount < thislength) {
        if(value[icount] != stype.value[icount]) {
         retvalue = false;
         break;
        }
        icount ++;
      }
    }else
     retvalue = false;
    return retvalue;
  }

/**
 * operator '!=' 
 * @param type
 * @return if type is not equal this then true otherwise false
 */
  public boolean notequal(Variable type) {
    return !equal(type);
  }

/**
 * operator '=' 
 * assign the type to this
 * @param type
 * @return new type
 */
  public Variable assign(Variable type) {
    if(value.length < ((String)type).value.length) {
      buf_size = ((String)type).value.length;
      value = new char[buf_size];
      System.arraycopy(((String)type).value, 0, value, 0, buf_size);
    }
    return this;
  }

/**
 * operator '+' 
 * the type plus this type
 * NOT USED IN THIS TYPE
 * @param type
 * @return new type
 */
  public Variable plus(Variable type) {
    return null;
  }

/**
 * operator '-' 
 * the type minus this type
 * NOT USED IN THIS TYPE
 * @param type
 * @return new type
 */
  public Variable minus(Variable type) {
    return null;
  }

/**
  * operator '/' 
  * division operator
  * NOT USED IN THIS TYPE
  * @param type
  * @return new type
  */
  public Variable div(Variable type) {
    return null;
  }

/**
  * operator '*' 
  * multiplication
  * NOT USED IN THIS TYPE
  * @param type
  * @return new type
  */
  public Variable mult(Variable type) {
    return null;
  }

/**
  * operator '<>' 
  * is this type contains type or not.
  * @param type
  * @return true if this type contains type otherwise false
  */
  public Variable contains(Variable type) {
    return null;
  }
}
